<?php

	include_once '../com/mss/model/Drug.php';
	include_once '../com/mss/accessor/DrugAccessor.php';

	class DrugService {
	
		public function saveAll($file) {
			$drugs = array();
			$handle = fopen($file,"r");
	
			if (($handle = fopen($file, "r")) !== FALSE) {
				while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
					$name = $data[0];
					$serial = $data[1];
					$unit = $data[2];
					$description = $data[3];
					
					$drug = new Drug("", $name, $serial, $unit, $description);
					array_push($drugs, $drug);
				}
				fclose($handle);
			} else {
				echo "I could not read it";
			}
			$drug_accessor = new DrugAccessor();
			$drug_accessor->saveAll($drugs);
		}
	
		public function selectAll() {
			$drug_accessor = new DrugAccessor();
			return $drug_accessor->selectAll();
		}
	}

?>